﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Booking.WPServiceData;

namespace Booking
{
    public partial class Thongtin : PhoneApplicationPage
    {
        public Thongtin()
        {
            InitializeComponent();
        }

        private void txtDiaChi_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            this.txtDiaChi.Text = "";
        }

        private void TenKhachHang_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            this.TenKhachHang.Text = "";
        }

        private void soDienThoai_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            this.soDienThoai.Text = "";
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            String Diachi = txtDiaChi.Text;
            String Hoten = TenKhachHang.Text;
            String sodt = soDienThoai.Text;
            ServiceSoapClient service = new ServiceSoapClient();
            var dataString  = "";
            int start = 0;
            foreach(int id in lib.DefinesClass.OrderState.Keys)
            {
                var spacString  = start++!=0?",":"";
                dataString += spacString + id + ":" + lib.DefinesClass.OrderState[id]; 
            }
            service.BookingCompleted += new EventHandler<BookingCompletedEventArgs>(fillbooking);
            service.BookingAsync(dataString, Diachi, sodt, Hoten);
        }


        private void fillbooking(Object sender, BookingCompletedEventArgs e)
        {
            MessageBox.Show(e.Result ? "Đặt món thành công!" : "Đặt món thất bại, vui lòng thử lại!, cảm ơn!.");
            if (e.Result)
            {
                lib.DefinesClass.OrderState =  new Dictionary<int,int>();
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
            }
            
        }
    }
}